package com.haiyou.common.constants;

import java.util.Map;
import java.util.Set;

import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.haiyou.common.system.Properties;


/**
 * 
 * 
 * @Description: 项目结构包分类
 * @author xingyuan
 * @date 2022年6月17日 下午4:32:49
 */
public class ServerDataConstants {

	/**
	 * 数据包基本包名
	 */
	public static final String data_base_package = "com.haiyou.data.";

	/**
	 * boss
	 */
	public static final String server_boss = data_base_package + ServerTypeConstants.server_boss;
	
	/**
	 * game
	 */
	public static final String server_game = data_base_package +  ServerTypeConstants.server_game;

	/**
	 * sdk
	 */
	public static final String server_sdk = data_base_package +  ServerTypeConstants.server_sdk;

	/**
	 * gift
	 */
	public static final String server_gift = data_base_package +  ServerTypeConstants.server_gift;

	
	/**
	 * boss 服务更新数据 boss
	 */
	public static final Set<String> server_boss_update = Sets.newHashSet(server_boss);
	
	/**
	 * 游戏服更新 game
	 */
	public static final Set<String> server_game_update = Sets.newHashSet(server_game,server_sdk);

	/**
	 * sdk 服务器更新sdk
	 */
	public static final Set<String> server_sdk_update = Sets.newHashSet(server_sdk);

	/**
	 * 礼包码服务更新 
	 */
	public static final Set<String> server_gift_update = Sets.newHashSet(server_gift);
	

	public static Map<String, Set<String>> maps = Maps.newHashMap();
	
	static {
		
		maps.put(ServerTypeConstants.server_boss, server_boss_update);
		
		maps.put(ServerTypeConstants.server_game, server_game_update);
		
		maps.put(ServerTypeConstants.server_gift, server_gift_update);
		
		//sdk 不执行更新
		//maps.put(ServerTypeConstants.server_sdk, server_sdk_update);
	}
	
	
	/**
	 * 判断是否需要启动异步定时数据库更新
	 * @return
	 */
	public static boolean contains(Class<?> classz) {
		
		String serverNodeType = Properties.server_node_type();
		
		if(!StringUtils.hasLength(serverNodeType)) {
			return false;
		}
		
		Set<String> keys = maps.getOrDefault(serverNodeType, null);
		
		if(ObjectUtils.isEmpty(keys)) {
			return false;
		}
		
		for (String key : keys) {
			
			if(classz.toString().contains(key)) {
				return true;
			}
		}
		
		return false;
	}
	
	

	
	
	
	
	
}
